package edu.suse.service.impl;


import edu.suse.common.base.RespResult;
import edu.suse.entity.Collection;
import edu.suse.mapper.CollectionMapper;
import edu.suse.service.CollectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//业务逻辑处理：日志、事务、安全等
@Service // = new SysUserServiceImpl();
@Slf4j
public class CollectionServiceImpl implements CollectionService {
    // 调用Mapper层
    @Resource
    private CollectionMapper collectionMapper;

//查找所有
    @Override
    public RespResult findCollectionAll(Integer currentPage,Integer pageSize) {
        currentPage=(currentPage-1)*pageSize;
        List<Collection>collectionList =  collectionMapper.queryCollectionList(currentPage,pageSize);
        log.info("collect:{}",collectionList);
        return RespResult.success(collectionList);
    }
    //查找页码
    @Override
    public RespResult getCollectionList(Integer pageSize) {
        Integer collectionNum =  collectionMapper.getCollectionListNum();
//        Integer totalPageNum = (collectionNum +pageSize - 1) / pageSize;
//        log.info("collect:{}",collectionNum);
//        log.info("collect:{}",totalPageNum);
        return RespResult.success(collectionNum);
    }
//    添加
    @Override
    public RespResult addCollectionAll(Collection addList) {
        Collection collection = collectionMapper.addCollection(addList);
        if(collection != null ){//添加成功
            return RespResult.success("添加成功!");
        }else{//添加失败！
            return RespResult.error("添加失败!");
        }
    }
//    删除
    @Override
    public RespResult deleteCollection(String id) {
        Collection collection = collectionMapper.delCollection(id);
        log.info("collect",collection);
        if(collection == null ){
            return RespResult.success("success");

        }else{//添加失败！
            return RespResult.error("error");
        }
    }
    //    查找单个
    @Override
    public RespResult findCollectionById(String id) {
        List<Collection> collection = collectionMapper.findCollectionList(id);
        log.info("collect:{}",collection);
            return RespResult.success(collection);
    }
    //    模糊查找
    @Override
    public RespResult searchCollection(String searchCollection) {
        List<Collection> collection = collectionMapper.searchCollectionList(searchCollection);
        log.info("collect:{}",collection);
        return RespResult.success(collection);
    }
    //    朝代查找
    @Override
    public RespResult dynastyCollection() {
        List<Collection> collection = collectionMapper.dynastyCollectionAll();
        log.info("collect:{}",collection);
        return RespResult.success(collection);
    }
    //    朝代查找
    @Override
    public RespResult ascSort() {
        List<Collection> collection = collectionMapper.ascSortAll();
        log.info("collect:{}",collection);
        return RespResult.success(collection);
    }
    //    朝代查找
    @Override
    public RespResult dynastyCollevtionAll(String command) {
        List<Collection> collection = collectionMapper.dynastyCollectionAllList(command);
        log.info("collect:{}",collection);
        return RespResult.success(collection);
    }
    //    修改
    @Override
    public RespResult editCollection(Collection editList) {
        Collection collection = collectionMapper.editCollection(editList);
        if(collection != null ){//添加成功
            return RespResult.error("error");

        }else{//添加失败！
            return RespResult.success("success");
        }
    }

}
